﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace PCMDictionaryMerge
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 2)
            {
                var mainDictionary = ReadDictionary(@args[0]);
                var newWords = ReadDictionary(@args[1]);

                foreach (string word in newWords)
                {
                    if (!mainDictionary.Contains<string>(word))
                        mainDictionary.Add(word);
                }
                mainDictionary.Sort();
                File.Delete(args[0] + ".old");
                File.Move(args[0], args[0] + ".old"); // rename input file
                File.WriteAllLines(@args[0], mainDictionary.ToArray());
                // Empty word.txt file
                File.CreateText(@args[1]);
            }
        }

        private static List<string> ReadDictionary(string fileName)
        {
            var dictionaryFile =
                from line in File.ReadAllLines(@fileName)
                select line;

            List<string> result = new List<string>(dictionaryFile.ToList().Distinct<string>());

            return result;
        }
    }
}